import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const router = new VueRouter({
    // saveScrollPosition: true,
    scrollBehavior(to,from,savePosition){ // 在点击浏览器的“前进/后退”，或者切换导航的时候触发。
        if(savePosition) {
            return savePosition;
        }else{
            return {x:0,y:0}
        }
    },
    routes: [
        {
            path: '/login/index',
            meta: {dialog: true, title: '登陆'},
            component: require('./page/login/Login.vue').default,
            props: {dialog: true}
        },
        {
            path: '/',//后台框架页面
            component: require('./components/layout/Index.vue').default,
            children: [
                //    弹窗类组件
                // {
                //     path: '/dialog/operation/money.invoice/:id?',
                //     meta: {dialog: true, title: '操作发票',width: 'w600'},
                //     component: require('./page/dialog/Invoice.vue').default,
                //     props: {dialog: true}
                // },
                {
                    path: '/dialog/show/:model/:id?',
                    meta: {dialog: true, title: '详情',width: 'w1000'},
                    component: require('./page/dialog/CommonForm.vue').default,
                    props: true
                },
                {
                    path: '/dialog/edit/:model/:id?',
                    meta: {dialog: true, title: '编辑',width: 'w1000'},
                    component: require('./page/dialog/CommonForm.vue').default,
                    props: true
                },
                {
                    path: '/dialog/curd/:model/:actn?/:query?/',
                    meta: {dialog: true, title: '数据操作'},
                    component: require('./page/dialog/CommonTable.vue').default,
                    props: {dialog: true}
                },
                //    弹窗类组件
                {
                    path: '/',
                    // component: require('./page/Index.vue').default,
                    redirect: '/order/noworder'
                },
                {
                    path: '/demo',
                    component: require('./page/Demo.vue').default
                },
                {
                    path: '/config/',
                    component: require('./page/Config.vue').default,
                    children: [
                        {
                            path: 'edit/:model/:id',
                            meta: {dialog: true, title: '编辑'},
                            components: {
                                dialog: require('./components/module/Form.vue').default
                            },
                            props: {dialog: true},
                        }
                    ]
                },
                {
                    path: 'curd/:model/:actn?/:query?/',
                    component: require('./page/List.vue').default,
                },
                {
                    path: '/edit/:model/:id?',
                    component: require('./page/Edit.vue').default
                },
                {
                    path: '/show/:model/:id?',
                    component: require('./page/Show.vue').default
                },

                {
                    path: '/im/:id?',
                    component: require('./components/module/IM.vue').default
                },
                {
                    path: '*',//404
                    component: require('./page/404.vue').default
                }
            ]
        },

    ]
});

export default router;
